/**
 * Copyright (c) 2018, wuxie All rights reserved.
 * qq:16349023,mail:16349023@qq.com
 * 未经许可禁止任何人通过任何渠道使用、修改源代码.
 * 项目名称 : wxcloud
 *
 * @version V1.0
 */
package cn.xo68.boot.auth.core.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *  oauth2 凭证
 * @author wuxie
 * @date 2018/8/5 20:49
 *
 */

public class Oauth2Principal implements Principal, Serializable {

    private String userId;
    private String account;
    private String userName;
    private String sex;
    private Integer userType;
    private Date birthday;
    private String phone;
    private String email;

    private String accessToken;
    private String clientId;

    private List<String> roles;
    private List<String> permissions;

    @JsonIgnore
    @Override
    public String getName() {
        return userId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }

    public void addPermission(String permission){
        if(this.permissions==null){
            this.permissions=new ArrayList<>();
        }
        this.permissions.add(permission);
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }
    public void addRole(String role){
        if(this.roles==null){
            this.roles=new ArrayList<>();
        }
        this.roles.add(role);
    }

    public void addRoles(List<String> roles){
        if(this.roles==null){
            this.roles=new ArrayList<>();
        }
        this.roles.addAll(roles);
    }

    @Override
    public String toString() {
        return this.accessToken;
    }
}
